package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.UseDoDao;
import ysq.xyg.model.UseDo;
import ysq.xyg.service.UseDoService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yu sheng qiang
 * @create 2017-03-22 15:37
 **/
@Service("useDoService")
public class UseDoServiceImpl extends BaseServiceImpl<UseDo> implements UseDoService {
    @Resource
    private UseDoDao useDoDao;

    @Autowired
    public void setBaseDao(UseDoDao useDoDao) {
        this.baseDao = useDoDao;
    }

    @Override
    public PageInfo<UseDo> pageInfo(UseDo useDo, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        PageHelper.orderBy(" create_time desc");
        //通用Example查询
        Example example = new Example(UseDo.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtil.isNotEmpty(useDo.getName())) {
            criteria.andLike("name","%"+useDo.getName()+"%");
        }
        if (StringUtil.isNotEmpty(useDo.getContent())) {
            criteria.andLike("content","%"+useDo.getContent()+"%");
        }
        if (StringUtil.isNotEmpty(useDo.getType())) {
            criteria.andEqualTo("type",useDo.getType());
        }
        List<UseDo> list=useDoDao.selectByExample(example);
        return new PageInfo<UseDo>(list);
    }
    @Override
    public List<UseDo> list(UseDo useDo) {
        //通用Example查询
        Example example = new Example(UseDo.class);
        example.setOrderByClause(" create_time desc");
        Example.Criteria criteria = example.createCriteria();
        if (StringUtil.isNotEmpty(useDo.getName())) {
            criteria.andLike("name","%"+useDo.getName()+"%");
        }
        if (StringUtil.isNotEmpty(useDo.getType())) {
            criteria.andEqualTo("type",useDo.getType());
        }
        List<UseDo> list=useDoDao.selectByExample(example);
        return list;
    }
}
